import { setToken, getToken, removeToken } from '@/utils/storage'
import { getUserInfo } from '@/api/login'
export default {
  namespaced: true,
  state: {
    token: getToken(),
    userInfo: {}
  },
  mutations: {
    setToken(state, token) {
      state.token = token
      setToken(token)
    },
    removeToken(state) {
      state.token = {}
      removeToken()
    },
    getUser(state, userInfo) {
      state.userInfo = userInfo
    }
  },
  actions: {
    async getUserInfo(context) {
      const res = await getUserInfo()
      // console.log(res)
      context.commit('getUser', res.data)
    }
  }
}
